<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
        </style>
        <p:panel style="height: 250px"> 
            <h2>View Document Flow</h2>

            <h:form id="searchSOForm" >
                <p:ajaxStatus style="width: 16px;height: 16px;">
                    <f:facet name="start">
                        <h:graphicImage value="./../images/ajaxloading.gif"/>
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value=""/>
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />

                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel for="salesOrderIdStr" style="font-weight: bold" value="Enter Sales Order Id: "/>
                    <h:inputText required="true" label="Sales Order" requiredMessage="Sales order Id is required."
                                 id="salesOrderIdStr" value="#{documentFlowManagerBean.salesOrderIdStr}"/>
                    <p:commandButton update="searchSOForm" oncomplete="soDialog.show();" image="ui-icon ui-icon-search"/>    
                </h:panelGrid>
                <p:commandButton id="button" value="View" ajax="true" update="displayDetail" action="#{documentFlowManagerBean.selectSalesOrder}"/>
            </h:form>
        </p:panel>

        <h:form id="displayDetail" >
            <p:panel header="View Options" rendered="#{documentFlowManagerBean.renderDetailPanel()}">
                <br/>
                <p:lightBox iframe="true" width="80%" height="80%" rendered="#{documentFlowManagerBean.renderViewSO()}">  
                    <h:outputLink value="/merlion-war/CommonUtility/jasperreports">
                        <f:param name="type" value="salesOrder" /> 
                        <f:param name="strId" value="#{documentFlowManagerBean.selectedSalesOrder.id}" />
                        <h:outputText value="View Sales Order: #{documentFlowManagerBean.selectedSalesOrder.salesOrderIdStr}" />
                    </h:outputLink> 
                </p:lightBox>
                <br/>
                <p:lightBox iframe="true" width="80%" height="80%" rendered="#{documentFlowManagerBean.renderViewSQ()}">  
                    <h:outputLink value="/merlion-war/CommonUtility/jasperreports">
                        <f:param name="type" value="salesQuotation" /> 
                        <f:param name="strId" value="#{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.salesQuotation.id}" />
                        <h:outputText value="View Sales Quotation: #{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.salesQuotation.sqNumber}" />
                    </h:outputLink> 
                </p:lightBox> 
                <br/>
                <p:lightBox iframe="true" width="80%" height="80%" rendered="#{documentFlowManagerBean.renderViewInvoice()}">
                    <c:forEach items="#{documentFlowManagerBean.selectedSalesOrder.deliveryOrders}" var="item">
                        <h:outputLink value="/merlion-war/CommonUtility/jasperreports">
                            <f:param name="type" value="invoice" /> 
                            <f:param name="strId" value="#{item.invoice.id}" />
                            <h:outputText value="View Invoice: #{item.invoice.invoiceId}" />
                        </h:outputLink> 
                        <br/>
                    </c:forEach>
                </p:lightBox>

                <br/>
                <p:commandLink value="View Uploaded Sales Quotation: #{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.salesQuotation.sqNumber}" update="uploadForm" onclick="viewUploads.show()" rendered="#{documentFlowManagerBean.renderViewSQUploaded()}"/>
                <br/>
                <br/>
                <p:commandLink value="View Uploaded Purchase Order: #{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.poNumber}" update="uploadForm2" onclick="viewUploads2.show()" rendered="#{documentFlowManagerBean.renderViewPOUploaded()}"/>
                <br/>
            </p:panel>
        </h:form>

        <p:dialog widgetVar="viewUploads" showEffect="explode" hideEffect="explode" height="1300" width="700">
            <h:form id="uploadForm">
                <p:panel header="Uploaded Sales Quotation" rendered="#{documentFlowManagerBean.renderViewSQUploaded()}">
                    <p:graphicImage value="#{facesContext.externalContext.requestContextPath}/../displayImage?id=#{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.salesQuotation.uploadedImage.id}" 
                                    height="1300" width="700"/>
                </p:panel>
            </h:form>
        </p:dialog>

        <p:dialog widgetVar="viewUploads2" showEffect="explode" hideEffect="explode" height="1300" width="700">
            <h:form id="uploadForm2">
                <p:panel header="Uploaded Purchase Order" rendered="#{documentFlowManagerBean.renderViewPOUploaded()}">
                    <p:graphicImage value="#{facesContext.externalContext.requestContextPath}/../displayImage?id=#{documentFlowManagerBean.selectedSalesOrder.purchaseOrder.uploadedImage.id}" 
                                    height="1300" width="700"/>
                </p:panel>
            </h:form>
        </p:dialog>

        <p:dialog header="searchSalesOrder" widgetVar="soDialog" hideEffect="explode" height="600" width="800">    
            <h:form id="soForm">
                <p:dataTable var="salesOrder" value="#{documentFlowManagerBean.allSalesOrders}"
                             emptyMessage="No Sales Orders found with given criteria" selection="#{documentFlowManagerBean.selectedSalesOrder}" selectionMode="single" widgetVar="sotbl">

                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <p:inputText id="globalFilter" onkeyup="sotbl.filter()" style="width:150px" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column filterBy="#{salesOrder.salesOrderIdStr}" 
                              headerText="Sales Order Id" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.salesOrderIdStr}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.purchaseOrder.poNumber}" 
                              headerText="PO Number" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.purchaseOrder.poNumber}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.clientId}"
                              headerText="Client Id" footerText="contains">
                        <h:outputText value="#{salesOrder.customer.clientId}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.companyName}"
                              headerText="Client Name" footerText="contains">
                        <h:outputText value="#{salesOrder.customer.companyName}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.category}" 
                              headerText="Customer Category" footerText="exact"
                              filterOptions="#{ssoManagerBean.categoryOptions}"
                              filterMatchMode="exact">
                        <h:outputText value="#{salesOrder.customer.category}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.dateStr}" 
                              headerText="Sales Order Date" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.dateStr}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.salesOrderStatus}"
                              headerText="Sales Order Status" footerText="exact"
                              filterOptions="#{ssoManagerBean.statusOptions}"
                              filterMatchMode="exact">
                        <outputText value="#{salesOrder.salesOrderStatus}" />
                    </p:column>
                </p:dataTable>
                <p:commandButton value="Select Sales Order" update="searchSOForm" oncomplete="soDialog.hide()"/>
            </h:form>
        </p:dialog>

    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
